#include<iostream>
using namespace std;
 int main(){
 	unsigned long n,k,test=1,value=0;
	cin>>n>>k; 	
 	test=test<<(n-1);
 	int r=1;
 	while(test){
		cout<<"test"<<test<<endl; 			
 		if(test&k){
 			r=r*2; 
 			if(r%4==2||r%4==3){ value=value|test; }
 			
		 }else{
		 	r=r*2-1;
			if(r%4==2||r%4==3){ value=value|test; }
		 }
		test=test>>1;
	}
	cout<<value;
 }
 
